# -*- coding: utf-8 -*-
"""
@Time ： 2021/8/2 21:33
@Auth ： Mr.掌心 2929184523
@Company ：特斯汀学院 @testingedu.com.cn
@Function ：请输入模块功能描述
"""
import os

from common.excel import OldExcel, NewExcel


def get_reader(srcfile=''):
    """
    获取读取excel的对象
    :param srcfile: excel文件路径
    :return:
    """
    reader = None
    # 如果打开的文件不存在，就报错
    if not os.path.isfile(srcfile):
        print("%s not exist!" % (srcfile))
        return reader

    if srcfile.endswith('.xls'):
        reader = OldExcel.Reader()
        reader.open_excel(srcfile)
        return reader

    if srcfile.endswith('.xlsx'):
        reader = NewExcel.Reader()
        reader.open_excel(srcfile)
        return reader

def get_writer(srcfile, dstfile):
    """
    获取写入excel的对象
    :param srcfile: excel的文件路径
    :return:
    """
    writer = None

    # 如果打开的文件不存在，就报错
    if not os.path.isfile(srcfile):
        print("%s not exist!" % (srcfile))
        return writer

    if srcfile.endswith('.xls'):
        writer = OldExcel.Writer()
        writer.copy_open(srcfile,dstfile)
        return writer

    if srcfile.endswith('.xlsx'):
        writer = NewExcel.Writer()
        writer.copy_open(srcfile,dstfile)
        return writer

if __name__ == '__main__':
    reader = get_reader('../../lib/电商项目用例.xlsx')
    sheetname = reader.get_sheets()
    print(sheetname)

    for sheet in sheetname:
        # 设置读取的sheet页面
        reader.set_sheet(sheet)
        # 读取当前sheet的所有行
        lines = reader.readline()
        for i in range(len(lines)):
            print(lines[i])
        print()

    writer = get_writer('../../lib/电商项目用例.xlsx','../../lib/test-电商项目用例.xlsx')
    sheetname = writer.get_sheets()
    writer.set_sheet(sheetname[0])
    writer.write(3,7,'PASS',3)
    writer.save_close()














